<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<link rel="STYLESHEET" href="lib.css" type='text/css' />
<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
<link rel='start' href='../index.html' title='Python documentation Index' />
<link rel="first" href="lib.html" title='Python library Reference' />
<link rel='contents' href='contents.html' title="Contents" />
<link rel='index' href='genindex.html' title='Index' />
<link rel='last' href='about.html' title='About this document...' />
<link rel='help' href='about.html' title='About this document...' />
<link rel="next" href="match-objects.html" />
<link rel="prev" href="node46.html" />
<link rel="parent" href="module-re.html" />
<link rel="next" href="match-objects.html" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name='aesop' content='information' />
<title>4.2.4 Regular Expression Objects </title>
</head>
<body>
<div class="navigation">
<div id='top-navigation-panel' xml:id='top-navigation-panel'>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="4.2.3 module Contents"
  href="node46.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></a></td>
<td class='online-navigation'><a rel="parent" title="4.2 re  "
  href="module-re.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up one Level' width='32' /></a></td>
<td class='online-navigation'><a rel="next" title="4.2.5 match Objects"
  href="match-objects.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></a></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></a></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></a></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="node46.html">4.2.3 Module Contents</a>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="module-re.html">4.2 re  </a>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="match-objects.html">4.2.5 Match Objects</a>
</div>
<hr /></div>
</div>
<!--End of Navigation Panel-->

<h2><a name="SECTION006240000000000000000"></a><a name="re-objects"></a>
<br>
4.2.4 Regular Expression Objects 
</h2>

<p>
Compiled regular expression objects support the following methods and
attributes:

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-415' xml:id='l2h-415' class="method">match</tt></b>(</nobr></td>
  <td><var>string</var><big>[</big><var>, pos</var><big>[</big><var>,
                                       endpos</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
  If zero or more characters at the beginning of <var>string</var> match
  this regular expression, return a corresponding
  <tt class="class">MatchObject</tt> instance.  Return <code>None</code> if the string does not
  match the pattern; note that this is different from a zero-length
  match.

<p>
<span class="note"><b class="label">Note:</b>
If you want to locate a match anywhere in
  <var>string</var>, use <tt class="method">search()</tt> instead.</span>

<p>
The optional second parameter <var>pos</var> gives an index in the string
  where the search is to start; it defaults to <code>0</code>.  This is not
  completely equivalent to slicing the string; the
  <code>'^'</code> pattern
  character matches at the real beginning of the string and at positions
  just after a newline, but not necessarily at the index where the search
  is to start.

<p>
The optional parameter <var>endpos</var> limits how far the string will
  be searched; it will be as if the string is <var>endpos</var> characters
  long, so only the characters from <var>pos</var> to <code><var>endpos</var> -
  1</code> will be searched for a match.  If <var>endpos</var> is less than
  <var>pos</var>, no match will be found, otherwise, if <var>rx</var> is a
  compiled regular expression object,
  <code><var>rx</var>.match(<var>string</var>, 0, 50)</code> is equivalent to
  <code><var>rx</var>.match(<var>string</var>[:50], 0)</code>.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-416' xml:id='l2h-416' class="method">search</tt></b>(</nobr></td>
  <td><var>string</var><big>[</big><var>, pos</var><big>[</big><var>,
                                        endpos</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
  Scan through <var>string</var> looking for a location where this regular
  expression produces a match, and return a
  corresponding <tt class="class">MatchObject</tt> instance.  Return <code>None</code> if no
  position in the string matches the pattern; note that this is
  different from finding a zero-length match at some point in the string.

<p>
The optional <var>pos</var> and <var>endpos</var> parameters have the same
  meaning as for the <tt class="method">match()</tt> method.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-417' xml:id='l2h-417' class="method">split</tt></b>(</nobr></td>
  <td><var>string</var><big>[</big><var>,
                                       maxsplit<code> = 0</code></var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Identical to the <tt class="function">split()</tt> function, using the compiled pattern.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-418' xml:id='l2h-418' class="method">findall</tt></b>(</nobr></td>
  <td><var>string</var><big>[</big><var>, pos</var><big>[</big><var>,
                                        endpos</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Identical to the <tt class="function">findall()</tt> function, using the compiled pattern.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-419' xml:id='l2h-419' class="method">finditer</tt></b>(</nobr></td>
  <td><var>string</var><big>[</big><var>, pos</var><big>[</big><var>,
                                        endpos</var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Identical to the <tt class="function">finditer()</tt> function, using the compiled pattern.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-420' xml:id='l2h-420' class="method">sub</tt></b>(</nobr></td>
  <td><var>repl, string</var><big>[</big><var>, count<code> = 0</code></var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Identical to the <tt class="function">sub()</tt> function, using the compiled pattern.
</dl>

<p>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
  <td><nobr><b><tt id='l2h-421' xml:id='l2h-421' class="method">subn</tt></b>(</nobr></td>
  <td><var>repl, string</var><big>[</big><var>,
                                      count<code> = 0</code></var><big>]</big><var></var>)</td></tr></table></dt>
<dd>
Identical to the <tt class="function">subn()</tt> function, using the compiled pattern.
</dl>

<p>
<dl><dt><b><tt id='l2h-422' xml:id='l2h-422' class="member">flags</tt></b></dt>
<dd>
The flags argument used when the RE object was compiled, or
<code>0</code> if no flags were provided.
</dl>

<p>
<dl><dt><b><tt id='l2h-423' xml:id='l2h-423' class="member">groupindex</tt></b></dt>
<dd>
A dictionary mapping any symbolic group names defined by
<tt class="regexp">(?P&lt;<var>id</var>&gt;)</tt> to group numbers.  The dictionary is empty if no
symbolic groups were used in the pattern.
</dl>

<p>
<dl><dt><b><tt id='l2h-424' xml:id='l2h-424' class="member">pattern</tt></b></dt>
<dd>
The pattern string from which the RE object was compiled.
</dl>

<p>

<div class="navigation">
<div class='online-navigation'>
<p></p><hr />
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="4.2.3 module Contents"
  href="node46.html"><img src='../icons/previous.png'
  border='0' height='32'  alt='Previous Page' width='32' /></a></td>
<td class='online-navigation'><a rel="parent" title="4.2 re  "
  href="module-re.html"><img src='../icons/up.png'
  border='0' height='32'  alt='Up one Level' width='32' /></a></td>
<td class='online-navigation'><a rel="next" title="4.2.5 match Objects"
  href="match-objects.html"><img src='../icons/next.png'
  border='0' height='32'  alt='Next Page' width='32' /></a></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
  href="contents.html"><img src='../icons/contents.png'
  border='0' height='32'  alt='Contents' width='32' /></a></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
  border='0' height='32'  alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
  href="genindex.html"><img src='../icons/index.png'
  border='0' height='32'  alt='Index' width='32' /></a></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="node46.html">4.2.3 Module Contents</a>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="module-re.html">4.2 re  </a>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="match-objects.html">4.2.5 Match Objects</a>
</div>
</div>
<hr />
<span class="release-info">Release 2.5.1, documentation updated on 18th April, 2007.</span>
</div>
<!--End of Navigation Panel-->
<address>
See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
</address>
</body>
</html>
